function Encrypt() {}
$.extend(Encrypt.prototype, {
  RsaInit: function() {
    var jsEncrypt = new JSEncrypt();
    //设置公钥
    jsEncrypt.setPublicKey(
      "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAL8gge9MGxaKQjyr5rXfwEC7AMsKM18xPYL7oQuD0OB7CPSrVgIW/vzhEmVI3+Gh+IV5CPTdpMyCYl0vb48fsi8CAwEAAQ=="
    );
    return jsEncrypt;
  },

  //RSA加密
  RsaEncrypt: function(string) {
    var encrypted = this.RsaInit().encrypt(string);
    return encodeURIComponent(encrypted);
  },
  /**
   * AES加密
   * string 加密字符串
   * key 加密秘钥
   * [iv 可以自定义传入]
   */
  AesEncrypt: function(string, key) {
    var encrypted = CryptoJS.AES.encrypt(string, CryptoJS.enc.Utf8.parse(key), {
      iv: CryptoJS.enc.Utf8.parse(key)
    });
    encrypted = CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
    return encodeURIComponent(encrypted);
  },

  /**
   * [encrypt 解密]
   * @return {[type]} [description]
   */
  AesDecrypt: function(string, key) {
    var decrypted = CryptoJS.AES.decrypt(string, CryptoJS.enc.Utf8.parse(key), {
      iv: CryptoJS.enc.Utf8.parse(key)
    });
    return decrypted.toString(CryptoJS.enc.Utf8);
  }
});
